package view;

import controller.TeacherCtrl;
import controller.addAdapter;
import controller.deleteAdapter;
import controller.updateAdapter;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.text.ParseException;
import java.util.Calendar;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.text.MaskFormatter;

/**
 *
 * @author cska
 * 
 */

public class TeacherWnd extends JFrame {

    protected GridBagConstraints c;
    protected TeacherCtrl ctrl;
    protected String login;
    protected JTabbedPane teacherPane;
    
    protected JPanel lessonTab;
    protected JComboBox subjectBox;
    protected JComboBox groupBox;
    protected JTable lessonTable;
    protected JTable skipTable;
    protected JButton addLesson, deleteLesson, updateLesson;
    protected JButton addSkip, deleteSkip, updateSkip;
    protected JPanel skipDatePanel;
    protected JFormattedTextField begin, end;
    protected JButton searchSkip;

    protected JPanel labTab;
    protected JComboBox subjectBox_l;
    protected JPanel labDatePanel;
    protected JFormattedTextField begin_l;
    protected JFormattedTextField end_l;
    protected JButton searchLab;
    protected JTable labTable;
    protected JButton addLab, deleteLab, updateLab;

    protected JPanel lab_studentTab;
    protected JComboBox labBox;
    protected JComboBox groupBox_ls;
    protected JTable lsTable;
    protected JTable interimTable;
    protected JButton addLab_Student, deleteLab_Student, updateLab_Student;
    protected JButton addInterim, deleteInterim, updateInterim;

    protected JLabel l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12, l13, l14;
    protected JScrollPane sp1, sp2, sp3, sp4, sp5;
    protected JPanel bp1, bp2, bp3, bp4, bp5;

    public TeacherWnd(String login) {
        super();
        setLayout(new GridBagLayout());
        this.login = login;
        ctrl = new TeacherCtrl(login);

        lessonTab = new JPanel(new GridBagLayout());
        initlessonTab();

        labTab = new JPanel(new GridBagLayout());
        initLabTab();

        lab_studentTab = new JPanel(new GridBagLayout());
        initLab_StudentTab();

        c = new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER,
                GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0);

        teacherPane = new JTabbedPane();
        teacherPane.addChangeListener(new tabChangeAdapter(this, teacherPane, ctrl));
        teacherPane.add("Журнал",lessonTab);
        teacherPane.add("Задания",labTab);
        teacherPane.add("Задание :: Студенты",lab_studentTab);
        add(teacherPane,c);

        reloadSubject();

        subjectBox.addItemListener(new subjectChangeAdapter(this));
        groupBox.addItemListener(new groupChangeAdapter(this));
        lessonTable.getSelectionModel().addListSelectionListener(new lessonChangeAdapter(this));
        searchSkip.addActionListener(new searchAdapter(this));

        reloadSubject_l();
        reloadLsTab();

        subjectBox_l.addItemListener(new subjectlChangeAdapter(this));
        searchLab.addActionListener(new searchlAdapter(this));
        labTable.getSelectionModel().addListSelectionListener(new labChangeAdapter(this));
        labBox.addActionListener(new labBoxChangeAdapter(this));
        groupBox_ls.addItemListener(new groupBox_lsChangeAdapter(this));
        lsTable.getSelectionModel().addListSelectionListener(new lsChangeAdapter(this));

        setDefaultCloseOperation(EXIT_ON_CLOSE);
        Dimension screen = getToolkit().getScreenSize().getSize();
        setSize(screen.width*3/4,screen.height*3/4);
        setLocation((screen.width/4)/2, (screen.height/4)/2);
        setVisible(true);
    }

    public void initlessonTab() {
        c = new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER,
                GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0);
        c.weighty = 0.0;
        c.weightx = 0.0;
        l1 = new JLabel("Предмет:", JLabel.RIGHT);
        lessonTab.add(l1,c);
        c.gridy = 1;
        l2 = new JLabel("Группа:", JLabel.RIGHT);
        lessonTab.add(l2,c);
        c.gridy = 3;
        c.gridx = 0;
        c.gridwidth = 2;
        c.weightx = 1.0;
        l14 = new JLabel("Список занятий", JLabel.CENTER);
        lessonTab.add(l14,c);
        c.gridx = 2;
        l3 = new JLabel("Список отсутсвующих", JLabel.CENTER);
        lessonTab.add(l3, c);
        c.gridx = 0;
        c.gridy = 4;
        c.weighty = 1.0;
        c.gridwidth = 2;
        lessonTable = new JTable() {
            @Override
            public boolean isCellEditable(int row, int column) {
                return false;
            }
        };
        sp5 = new JScrollPane(lessonTable);
        lessonTab.add(sp5,c);
        c.gridx = 2;
        skipTable = new JTable() {
            @Override
            public boolean isCellEditable(int row, int column) {
                return false;
            }
        };
        sp1 = new JScrollPane(skipTable);
        lessonTab.add(sp1,c);
        c.gridx = 1;
        c.gridy = 0;
        c.weightx = 1.0;
        c.weighty = 0.0;
        c.gridwidth = 3;
        subjectBox = new JComboBox();
        lessonTab.add(subjectBox,c);
        c.gridy = 1;
        groupBox = new JComboBox();
        lessonTab.add(groupBox,c);

        c.gridx = 0;
        c.gridy = 5;
        c.gridwidth = 2;
        c.weightx = 1.0;
        c.weighty= 0.0;
        bp5 = new JPanel(new GridBagLayout());
        lessonTab.add(bp5,c);
        c.gridwidth = 1;
        c.gridx = 0;
        c.gridy = 0;
        c.weightx = 0.3;
        c.anchor = GridBagConstraints.EAST;
        c.fill = GridBagConstraints.CENTER;
        addLesson = new JButton("Добавить");
        addLesson.addActionListener(new addAdapter(this, ctrl, addAdapter.ADD_LESSON));
        bp5.add(addLesson,c);
        c.gridx = 1;
        c.anchor = GridBagConstraints.CENTER;
        c.weightx = 0.0;
        deleteLesson = new JButton("Удалить");
        deleteLesson.addActionListener(new deleteAdapter(this, ctrl, deleteAdapter.DELETE_LESSON));
        bp5.add(deleteLesson,c);
        c.gridx = 2;
        c.weightx = 0.3;
        c.anchor = GridBagConstraints.WEST;
        updateLesson = new JButton("Изменить");
        updateLesson.addActionListener(new updateAdapter(this, ctrl, updateAdapter.UPDATE_LESSON));
        bp5.add(updateLesson,c);

        c.gridx = 2;
        c.gridy = 5;
        c.gridwidth = 2;
        c.weightx = 1.0;
        c.weighty= 0.0;
        c.fill = GridBagConstraints.HORIZONTAL;
        bp1 = new JPanel(new GridBagLayout());
        lessonTab.add(bp1,c);
        c.gridwidth = 1;
        c.gridx = 0;
        c.gridy = 0;
        c.weightx = 0.3;
        c.anchor = GridBagConstraints.EAST;
        c.fill = GridBagConstraints.CENTER;
        addSkip = new JButton("Добавить");
        addSkip.addActionListener(new addAdapter(this, ctrl, addAdapter.ADD_SKIP));
        bp1.add(addSkip,c);
        c.gridx = 1;
        c.anchor = GridBagConstraints.CENTER;
        c.weightx = 0.0;
        deleteSkip = new JButton("Удалить");
        deleteSkip.addActionListener(new deleteAdapter(this, ctrl, deleteAdapter.DELETE_SKIP));
        bp1.add(deleteSkip,c);
        c.gridx = 2;
        c.weightx = 0.3;
        c.anchor = GridBagConstraints.WEST;
        updateSkip = new JButton("Изменить");
        updateSkip.addActionListener(new updateAdapter(this, ctrl, updateAdapter.UPDATE_SKIP));
        bp1.add(updateSkip,c);

        c.gridx = 0;
        c.gridy = 2;
        c.gridwidth = 4;
        c.weightx = 1.0;
        c.anchor = GridBagConstraints.CENTER;
        c.fill = GridBagConstraints.HORIZONTAL;
        skipDatePanel = new JPanel(new GridBagLayout());
        lessonTab.add(skipDatePanel,c);
        c.gridy = 0;
        c.gridwidth = 1;
        c.weightx = 0.0;
        l4 = new JLabel("Период: с");
        skipDatePanel.add(l4,c);
        c.gridx = 1;
        c.weightx = 0.25;
        MaskFormatter mask = null;
        try {
            mask = new MaskFormatter("####.##.##");
        } catch (ParseException ex) {
            Logger.getLogger(TeacherWnd.class.getName()).log(Level.SEVERE, null, ex);
        }
        begin = new JFormattedTextField(mask);
        setDateField(begin,0);
        begin.setHorizontalAlignment(JFormattedTextField.CENTER);
        skipDatePanel.add(begin,c);
        c.gridx = 2;
        c.weightx = 0.0;
        l5 = new JLabel("по");
        skipDatePanel.add(l5,c);
        c.gridx = 3;
        c.weightx = 0.25;
        try {
            mask = new MaskFormatter("####.##.##");
        } catch (ParseException ex) {
            Logger.getLogger(TeacherWnd.class.getName()).log(Level.SEVERE, null, ex);
        }
        end = new JFormattedTextField(mask);
        setDateField(end,1);
        end.setHorizontalAlignment(JFormattedTextField.CENTER);
        skipDatePanel.add(end, c);
        c.gridx = 4;
        c.weightx = 0.0;
        searchSkip = new JButton("Поиск");
        skipDatePanel.add(searchSkip,c);

    }

    public void initLabTab() {
        c = new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER,
                GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0);
        c.weighty = 0.0;
        c.weightx = 0.0;
        l6 = new JLabel("Предмет:", JLabel.RIGHT);
        labTab.add(l6,c);
        c.gridy = 2;
        c.gridwidth = 2;
        c.weightx = 1.0;
        l7 = new JLabel("Список заданий", JLabel.CENTER);
        labTab.add(l7, c);
        c.gridy = 3;
        c.weighty = 1.0;
        labTable = new JTable() {
            @Override
            public boolean isCellEditable(int row, int column) {
                return false;
            }
        };
        sp2 = new JScrollPane(labTable);
        labTab.add(sp2,c);
        c.gridx = 1;
        c.gridy = 0;
        c.weightx = 0.9;
        c.weighty = 0.0;
        c.gridwidth = 1;
        subjectBox_l = new JComboBox();
        labTab.add(subjectBox_l,c);
        
        c.gridx = 0;
        c.gridy = 4;
        c.gridwidth = 2;
        c.weightx = 1.0;
        c.weighty= 0.0;
        bp2 = new JPanel(new GridBagLayout());
        labTab.add(bp2,c);
        c.gridwidth = 1;
        c.gridx = 0;
        c.gridy = 0;
        c.weightx = 0.3;
        c.anchor = GridBagConstraints.EAST;
        c.fill = GridBagConstraints.CENTER;
        addLab = new JButton("Добавить");
        addLab.addActionListener(new addAdapter(this, ctrl, addAdapter.ADD_LAB));
        bp2.add(addLab,c);
        c.gridx = 1;
        c.anchor = GridBagConstraints.CENTER;
        c.weightx = 0.0;
        deleteLab = new JButton("Удалить");
        deleteLab.addActionListener(new deleteAdapter(this, ctrl, deleteAdapter.DELETE_LAB));
        bp2.add(deleteLab,c);
        c.gridx = 2;
        c.weightx = 0.3;
        c.anchor = GridBagConstraints.WEST;
        updateLab = new JButton("Изменить");
        updateLab.addActionListener(new updateAdapter(this, ctrl, updateAdapter.UPDATE_LAB));
        bp2.add(updateLab,c);

        c.gridx = 0;
        c.gridy = 1;
        c.gridwidth = 2;
        c.weightx = 1.0;
        c.anchor = GridBagConstraints.CENTER;
        c.fill = GridBagConstraints.HORIZONTAL;
        labDatePanel = new JPanel(new GridBagLayout());
        labTab.add(labDatePanel,c);
        c.gridy = 0;
        c.gridwidth = 1;
        c.weightx = 0.0;
        l8 = new JLabel("Выдано: с");
        labDatePanel.add(l8,c);
        c.gridx = 1;
        c.weightx = 0.25;
        MaskFormatter mask = null;
        try {
            mask = new MaskFormatter("####.##.##");
        } catch (ParseException ex) {
            Logger.getLogger(TeacherWnd.class.getName()).log(Level.SEVERE, null, ex);
        }
        begin_l = new JFormattedTextField(mask);
        setDateField(begin_l,0);
        begin_l.setHorizontalAlignment(JFormattedTextField.CENTER);
        labDatePanel.add(begin_l,c);
        c.gridx = 2;
        c.weightx = 0.0;
        l9 = new JLabel("по");
        labDatePanel.add(l9,c);
        c.gridx = 3;
        c.weightx = 0.25;
        try {
            mask = new MaskFormatter("####.##.##");
        } catch (ParseException ex) {
            Logger.getLogger(TeacherWnd.class.getName()).log(Level.SEVERE, null, ex);
        }
        end_l = new JFormattedTextField(mask);
        setDateField(end_l,1);
        end_l.setHorizontalAlignment(JFormattedTextField.CENTER);
        labDatePanel.add(end_l, c);
        c.gridx = 4;
        c.weightx = 0.0;
        searchLab = new JButton("Поиск");
        labDatePanel.add(searchLab,c);
    }

    public void initLab_StudentTab() {
        c = new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0);

        l10 = new JLabel("Задание:", JLabel.RIGHT);
        lab_studentTab.add(l10,c);
        c.gridy = 1;
        l11 = new JLabel("Группа:", JLabel.RIGHT);
        lab_studentTab.add(l11,c);

        c.gridx = 1;
        c.gridy = 0;
        c.gridwidth = 3;
        c.weightx = 1.0;
        labBox = new JComboBox();
        lab_studentTab.add(labBox,c);
        c.gridy = 1;
        groupBox_ls = new JComboBox();
        lab_studentTab.add(groupBox_ls,c);

        c.gridx = 0;
        c.gridy = 2;
        c.gridwidth = 2;
        l12 = new JLabel("Список студентов", JLabel.CENTER);
        lab_studentTab.add(l12,c);
        c.gridx = 2;
        l13 = new JLabel("Промежуточные cдачи", JLabel.CENTER);
        lab_studentTab.add(l13,c);

        c.gridy = 3;
        c.weighty = 1.0;
        c.fill = GridBagConstraints.BOTH;
        c.gridx = 0;
        lsTable = new JTable() {
            @Override
            public boolean isCellEditable(int row, int column) {
                return false;
            }
        };
        sp3 = new JScrollPane(lsTable);
        sp3.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        sp3.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
        lab_studentTab.add(sp3,c);
        c.gridx = 2;
        interimTable = new JTable() {
            @Override
            public boolean isCellEditable(int row, int column) {
                return false;
            }
        };
        sp4 = new JScrollPane(interimTable);
        sp4.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        sp4.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
        lab_studentTab.add(sp4,c);

        c.gridx = 0;
        c.gridy = 4;
        c.weighty = 0.0;
        bp3 = new JPanel(new GridBagLayout());
        lab_studentTab.add(bp3,c);
        c.gridx = 2;
        bp4 = new JPanel(new GridBagLayout());
        lab_studentTab.add(bp4,c);

        c.gridx = 0;
        c.gridy = 0;
        c.gridwidth = 1;
        c.weightx = 1.0;
        c.anchor = GridBagConstraints.EAST;
        c.fill = GridBagConstraints.CENTER;
        addLab_Student = new JButton("Добавить");
        addLab_Student.addActionListener(new addAdapter(this, ctrl, addAdapter.ADD_LS));
        bp3.add(addLab_Student,c);
        c.gridx = 1;
        c.anchor = GridBagConstraints.CENTER;
        c.weightx = 0.0;
        deleteLab_Student = new JButton("Удалить");
        deleteLab_Student.addActionListener(new deleteAdapter(this, ctrl, deleteAdapter.DELETE_LS));
        bp3.add(deleteLab_Student,c);
        c.gridx = 2;
        c.anchor = GridBagConstraints.WEST;
        c.weightx = 1.0;
        updateLab_Student = new JButton("Изменить");
        updateLab_Student.addActionListener(new updateAdapter(this, ctrl, updateAdapter.UPDATE_LS));
        bp3.add(updateLab_Student,c);

        c.gridx = 0;
        c.gridy = 0;
        c.gridwidth = 1;
        c.weightx = 1.0;
        c.anchor = GridBagConstraints.EAST;
        c.fill = GridBagConstraints.CENTER;
        addInterim = new JButton("Добавить");
        addInterim.addActionListener(new addAdapter(this, ctrl, addAdapter.ADD_INTERIM));
        bp4.add(addInterim,c);
        c.gridx = 1;
        c.anchor = GridBagConstraints.CENTER;
        c.weightx = 0.0;
        deleteInterim = new JButton("Удалить");
        deleteInterim.addActionListener(new deleteAdapter(this, ctrl, deleteAdapter.DELETE_INTERIM));
        bp4.add(deleteInterim,c);
        c.gridx = 2;
        c.anchor = GridBagConstraints.WEST;
        c.weightx = 1.0;
        updateInterim = new JButton("Изменить");
        updateInterim.addActionListener(new updateAdapter(this, ctrl, updateAdapter.UPDATE_INTERIM));
        bp4.add(updateInterim,c);
    }

    public void setDateField(JFormattedTextField field, int mode) {
        Calendar cal = Calendar.getInstance();
        cal = Calendar.getInstance();
        int day = 1;
        int month = (1 + cal.get(Calendar.MONTH));
        int year = cal.get(Calendar.YEAR);
        if (mode == 1)
            day = (month != 2) ? ((month <= 7) ? 30 + month%2 : 31 - month%2) : ((year%400 == 0) || (year%4 == 0) && (year%25 != 0) ? 29: 28);
        String date_str = year + "." + (month < 10 ? "0" + month : month ) + "." + (day < 10 ? "0" + day : day);
        field.setText(date_str);
    }

    public int getSubject() {
        return subjectBox.getSelectedIndex();
    }

    public int getGroup() {
        return groupBox.getSelectedIndex();
    }

    public String getBegin() {
        return begin.getText();
    }

    public String getEnd() {
        return end.getText();
    }

    public int getLesson() {
        return lessonTable.getSelectedRow();
    }

    public int getSkip() {
        return skipTable.getSelectedRow();
    }

    public int getSubject_l() {
        return subjectBox_l.getSelectedIndex();
    }

    public String getBegin_l() {
        return begin_l.getText();
    }

    public String getEnd_l() {
        return end_l.getText();
    }

    public int getLab() {
        return labTable.getSelectedRow();
    }

    public void setLab(int index) {
        labTable.getSelectionModel().setSelectionInterval(index, index);
    }

    public int getLab_box() {
        return labBox.getSelectedIndex();
    }

    public int getGroup_ls() {
        return groupBox_ls.getSelectedIndex();
    }

    public int getLs() {
        return lsTable.getSelectedRow();
    }

    public int getInterim() {
        return interimTable.getSelectedRow();
    }

    public void reloadSubject() {
        subjectBox.setModel(ctrl.subjectComboBox());
        reloadGroup();
    }

    public void reloadGroup() {
        groupBox.setModel(ctrl.groupComboBox(getSubject()));
        reloadLesson();
    }

    public void reloadLesson() {
        lessonTable.setModel(ctrl.lessonTable(getSubject(), getGroup(), getBegin(), getEnd()));
        reloadSkip();
    }

    public void reloadSkip() {
        skipTable.setModel(ctrl.skipTable(getSubject(), getGroup(), getLesson(), getBegin(), getEnd()));
    }

    public void reloadSubject_l() {
        subjectBox_l.setModel(ctrl.subjectComboBox());
        reloadLab();
    }

    public void reloadLab() {
        labTable.setModel(ctrl.labTable(getSubject_l(), getBegin_l(), getEnd_l()));
        reloadLsTab();
    }

    public void reloadLab_box() {
        labBox.setModel(ctrl.labBox(getSubject_l(), getBegin_l(), getEnd_l()));
        labBox.setSelectedIndex(getLab());
    }

    public void reloadGroup_ls() {
        groupBox_ls.setModel(ctrl.groupComboBox(getSubject_l()));
    }

    public void reloadLsTab() {
        if (getLab() != -1) {
            reloadLab_box();
            reloadGroup_ls();
            reloadLs();
            teacherPane.setEnabledAt(2, true);
        } else
            teacherPane.setEnabledAt(2, false);
    }

    public void reloadLs() {
        if (getGroup_ls() == -1) reloadGroup_ls();
        lsTable.setModel(ctrl.lab_studentTable(ctrl.getLab(getSubject_l(), getBegin_l(), getEnd_l(), getLab()),ctrl.getGroup(getSubject_l(), getGroup_ls())));
        reloadInterim();
    }

    public void reloadInterim() {
        interimTable.setModel(ctrl.interimTable(getSubject_l(), getLab(), getGroup_ls(), getBegin_l(), getEnd_l(), getLs()));
    }

    class tabChangeAdapter implements ChangeListener {

        protected TeacherWnd teacher;
        protected JTabbedPane teacherPane;
        protected TeacherCtrl ctrl;

        public tabChangeAdapter(TeacherWnd teacher, JTabbedPane teacherPane, TeacherCtrl ctrl) {
            this.teacher = teacher;
            this.teacherPane = teacherPane;
            this.ctrl = ctrl;
            stateChanged(null);
        }

        public void stateChanged(ChangeEvent e) {
            int index = teacherPane.getSelectedIndex();
            String s = ctrl.getTeacher().toString() + " :: ";
            switch (index) {
                case 0:
                    s += "Журнал";
                    break;
                case 1:
                    s += "Задания";
                    break;
                case 2:
                    s += "Задание :: Студенты";
                    break;
            }
            teacher.setTitle(s);
        }

    }

    class subjectChangeAdapter implements ItemListener {

        protected TeacherWnd teacher;

        public subjectChangeAdapter(TeacherWnd teacher) {
            this.teacher = teacher;
        }

        public void itemStateChanged(ItemEvent e) {
            teacher.reloadGroup();
        }

    }

    class groupChangeAdapter implements ItemListener {

        protected TeacherWnd teacher;

        public groupChangeAdapter(TeacherWnd teacher) {
            this.teacher = teacher;
        }

        public void itemStateChanged(ItemEvent e) {
            reloadLesson();
        }

    }

    class searchAdapter implements ActionListener {

        protected TeacherWnd teacher;

        public searchAdapter(TeacherWnd teacher) {
            this.teacher = teacher;
        }
        
        public void actionPerformed(ActionEvent e) {
            teacher.reloadLesson();
        }

    }

    class lessonChangeAdapter implements ListSelectionListener {

        protected TeacherWnd teacher;

        public lessonChangeAdapter(TeacherWnd teacher) {
            this.teacher = teacher;
        }

        public void valueChanged(ListSelectionEvent e) {
            teacher.reloadSkip();
        }

    }

    class subjectlChangeAdapter implements ItemListener {

        protected TeacherWnd teacher;

        public subjectlChangeAdapter(TeacherWnd teacher) {
            this.teacher = teacher;
        }

        public void itemStateChanged(ItemEvent e) {
            teacher.reloadLab();
        }

    }

    class searchlAdapter implements ActionListener {

        protected TeacherWnd teacher;

        public searchlAdapter(TeacherWnd teacher) {
            this.teacher = teacher;
        }

        public void actionPerformed(ActionEvent e) {
            teacher.reloadLab();
        }

    }

    class labChangeAdapter implements ListSelectionListener {

        protected TeacherWnd teacher;
        
        public labChangeAdapter(TeacherWnd teacher) {
            this.teacher = teacher;
            teacher.reloadLab();
        }

        public void valueChanged(ListSelectionEvent e) {
            reloadLsTab();
        }

    }

    class labBoxChangeAdapter implements ActionListener {

        protected TeacherWnd teacher;

        public labBoxChangeAdapter(TeacherWnd teacher) {
            this.teacher = teacher;
        }

        public void actionPerformed(ActionEvent e) {
            setLab(teacher.getLab_box());
            teacher.reloadLs();
        }

    }

    class groupBox_lsChangeAdapter implements ItemListener {

        protected TeacherWnd teacher;

        public groupBox_lsChangeAdapter(TeacherWnd teacher) {
            this.teacher = teacher;
        }

        public void itemStateChanged(ItemEvent e) {
            reloadLs();
        }

    }

    class lsChangeAdapter implements ListSelectionListener {

        protected TeacherWnd teacher;

        public lsChangeAdapter(TeacherWnd teacher) {
            this.teacher = teacher;
            teacher.reloadInterim();
        }

        public void valueChanged(ListSelectionEvent e) {
            teacher.reloadInterim();
        }

    }

}
